<template>
  <div class="tool-local-image">
    <w-nav-bar
      title="本地图片识别"/>
    <div class="up-image-box w-flex-center">
      <w-image-up
        ref="UP_IMAGE"
        :oss="false"/>
    </div>
    <div class="dentify-but-bg w-max-btn">
      <x-button
        @click.native="upImage"
        type="primary">识别</x-button>
    </div>
    <w-result
      ref="WResult"/>
  </div>
</template>

<script>
  import { XButton } from 'vux'
  import WImageUp from '@/components/global/imageUp/server'
  import WResult from './result'

  export default {
    name: 'ToolLocalImage',
    components: {
      WImageUp,
      XButton,
      WResult
    },
    methods: {
      /**
       * 上传图片
       */
      upImage() {
        this.$w_popview.showLoading('识别中...')
        this.$refs['UP_IMAGE'].upImage ().then((data) => {
          this.$refs['WResult'].imageDentify ('localTextIdentify', {
            fileUrl: data.path
          })
        }).catch((err) => {
          this.$w_popview.msgError(err.msg)
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .tool-local-image {
    .up-image-box {
      padding: 20px 0;
    }

    .dentify-but-bg {
      text-align: center;
    }
  }

</style>
